from machine import I2C
from machine import SPI, Pin
import icm20948, utime
import st7789

'''
gyroScope will transfrom a point (x, y)
when you call it
init: imu 
'''

class accData(object):
    def __init__(self, imu):
        self.msgAcc = [0]*2
        self.imu = imu
        self.imu.dataready()
        self.mark = 0

    def getAccFunc(self):
        self.msgAcc[0] = self.imu.acc_x() / 50
        self.msgAcc[1] = self.imu.acc_y() / 50

    def handleAccData(self):
        self.imu.dataupdate()
        self.getAccFunc()
        return [self.msgAcc[0], self.msgAcc[1]]


# Acc Test

# init subThread: get accelerate from gyroscope sensor per 0.2s
# getAcc.init(type = Timer.PERIODIC, callback = getAccFunc, ticks = 20)

# main Thread
# when you want to control some functions like ST7789, networkSocket
# you must handle it in mainthread.

# runCnt = 0
# strToPrint = [0]*2
# while runCnt <= 1000:
#     imu.dataupdate()
#     print('Main thread is running... {}'.format(runCnt))
#     strToPrint[0] = "acc_x: %.3f" % p.msgAcc[0]
#     strToPrint[1] = "acc_y: %.3f" % p.msgAcc[1]
#     display.draw_string(p.x, p.y, strToPrint[0], color = p.color, bg = st7789.color565(255,255,255), size = 3)
#     display.draw_string(p.x, p.y+40, strToPrint[1], color = p.color, bg = st7789.color565(255,255,255), size = 3)
#     utime.sleep_ms(10)
#     runCnt += 1
# print('main thread ended.')
# getAcc.deinit()